var $1;
if($1=(opener.$||parent.$)){
	var style = $1("head").find("link[href$=style.css]").attr("href");
	$("head").find("link[href$=style.css]").attr("href",style);
}
	
var isLoadedMore = false; //用于判断是否第一次加载此页面，控制分页条
$(function(){
	var content = $.getParam("key");
	var pageno = $.getParam("pageno");
	bindPage(content,20,pageno,true);
})

//绑定页面数据
function bindPage(content,pagesize,pageno,isTotal){
	pagesize = pagesize||20;
	pageno = pageno||1;
	var condition = "title like '%"+content+"%' or CONTENT like '%"+content+"%'";
	
	//因为url中带有中文，所以需要转码，而且需要进行两次转码（进行一次转码，在后台解码会有错误）
	var url = "/category/"+0+"/entity?sign=6&condition="+encodeURI(condition)+"&pagesize="+pagesize+"&pageno="+pageno+"&is_total="+isTotal;
	url = encodeURI(url);
	//url = escape(url);
	$.get(url,function(json){
        var data = json;
        data = data.result || [];
        var html = [];
        document.title = "搜索结果";
        html.push("<h3><span class='fl h3_cn'>搜索结果</span></h3><div class='innew_line'><ul>");
        for(var i=0;i<data.length;i++){
			var d = data[i];
			var entityId = d.entity_id;
			var title = d.title;
	        var createDate = d.create_date;
	        html.push("<li><a href='_"+entityId+".html' class='fl' target='_blank' title='"+title+"'>" + title +"</a><time class='newline_time'>"+createDate+"</time></li>");
        }
        html.push("</ul></div>");
        $("#content").html(html.join(""));
        
        if(json.total>1 && !isLoadedMore){
        	$("#content").after("<div id='pagebar'></div>");
        	$.pageBar('pagebar',json.total,pagesize,pageno,function(pageindex){
				bindPage(categoryId,pagesize,pageindex);
			})
			isLoadedMore = true;
        }
    });
}